#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<algorithm>

using namespace std;

typedef pair<int, int> PII;

const int N = 5010;

PII segs[N];
int n;
int maxv1 = 0, maxv2 = 0;

void merge()
{
    int st = segs[0].first, ed = segs[0].second;
    for (int i = 0; i < n; i++)
    {
        int a = segs[i].first, b = segs[i].second;
        if (a <= ed) ed = max(ed, segs[i].second);
        else
        {
            maxv1 = max(maxv1, ed - st);
            maxv2 = max(maxv2, a - ed);
            st = a, ed = b;
        }
    }
    maxv1 = max(maxv1, ed - st);
    printf("%d %d\n", maxv1, maxv2);
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        int st, ed;
        scanf("%d%d", &st, &ed);
        segs[i] = { st,ed };
    }

    sort(segs, segs + n);
    merge();
    return 0;
}

